<?php

namespace IDock\Insurance\AICS\Response;

use IDock\Http\Response;
use IDock\Insurance\AICS\Response\AllAICSResponse;
use IDock\Printer\VehicleActualValuePrinter;
use IDock\Visitor\VehicleActualValueVisitor;

class VehicleActualValueResponse extends AllAICSResponse
{

    /**
     * @var VehicleActualValueVisitor $visitor
     */
    public $visitor;

    /**
     * @param $visitor
     */
    public function setVisitor($visitor): void
    {
        $this->visitor = $visitor;
    }

    public function printerInit(): Response
    {
        $vehicleActualValuePrinter = new VehicleActualValuePrinter();
        $vehiclePrice = $this->visitor->vehiclePrice;

        $vehicleActualValuePrinter->actualRate = '0.0060';

        $monthDiff = $this->visitor->monthDiff;

        $actualValue = round($vehiclePrice * (1 - $monthDiff * $vehicleActualValuePrinter->actualRate));

        $actualValueMostMin = round($vehiclePrice * 0.2);

        $actualValueMostMax = round($vehiclePrice * 1.3);

        if (($monthDiff >= 9 && $monthDiff < 96)) {
            //旧燃油车
            $actualValue = round($actualValue * 0.7, 2);
        } elseif ($monthDiff >= 96) {
            $actualValue = round($actualValue * 0.5, 2);
        }


        $vehicleActualValuePrinter->actualValue = max($actualValue, $actualValueMostMin);

        $vehicleActualValuePrinter->actualRate = (string)($vehicleActualValuePrinter->actualRate * 100);

        $vehicleActualValuePrinter->actualValueMin = $actualValueMostMin;

        $vehicleActualValuePrinter->actualValueMax = $actualValueMostMax;

        $this->printer = $vehicleActualValuePrinter;

        return $this;
    }
}
